/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package qltv;

import Controller.ChiTietPhieuMuonController;
import Controller.PhieuMuonController;
import Controller.SachController;
import DataAccess.ChiTietPhieuMuon;
import DataAccess.DocGia;
import DataAccess.Sach;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Vector;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author My PC
 */
public class KiemTraform extends javax.swing.JFrame implements IMuonSach{

    /**
     * Creates new form KiemTraform
     */
    ChiTietPhieuMuonController objControl=new ChiTietPhieuMuonController();
    SachController sachControl=new SachController();
    PhieuMuonController pmControl=new PhieuMuonController();
    private String[] strKiemTra={"Mã phiếu mượn","Mã sách","Tên sách","Ngày hẹn trả","Tình trạng sách"};
    ArrayList<IKiemTra> lstKT;
    public KiemTraform() {
        initComponents();
        lstKT=new ArrayList<IKiemTra>();

                }
    @Override
    public void Remove(IKiemTra kt)
    {
        lstKT.remove(kt);
    }
    @Override
    public void Register(IKiemTra kt)
    {
        lstKT.add(kt);
    }
    
    @Override
    public void Notify(ChiTietPhieuMuon ctpm,Date ngayhentra)
    { 
        for(IKiemTra kt: lstKT)
    {
            kt.Update(ctpm,ngayhentra);
    }
    }
    int dgID;
    public KiemTraform(DocGia dg, List<ChiTietPhieuMuon> lstCTPM) {
        initComponents();
        dgID=id;
        DisplayDocGia(dg, lstCTPM);
    }
    int id;
    ArrayList<ChiTietPhieuMuon> lst=new ArrayList<>();
    ArrayList<Date> lstdate=new ArrayList<>();
    public void DisplayDocGia(DocGia dg, List<ChiTietPhieuMuon> lstCTPM)
    {
        id=dg.getDocGiaId();
        lbTenDocGia.setText(lbTenDocGia.getText()+ " "+ dg.getTenDocGia());
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    String s = df.format(dg.getNgaySinh());
        lbNgaySinh.setText(lbNgaySinh.getText()+" "+s);
        lbGioiTinh.setText(lbGioiTinh.getText()+" "+ dg.getGioiTinh());
        lbNgheNghiep.setText(lbNgheNghiep.getText()+" "+dg.getNgheNghiep());
        lbDonVi.setText(lbDonVi.getText()+" "+dg.getDonVi());
        lbNgayLamThe.setText(lbNgayLamThe.getText()+" "+df.format(dg.getNgayLamThe()));
        lbNgayHetHan.setText(lbNgayHetHan.getText()+" "+df.format(dg.getNgayHetHan()));
        lbEmail.setText(lbEmail.getText()+" "+dg.getEmail());
      //  objControl.GetCTPMByDocGia(id, jTable1);
        
        DefaultTableModel tableModel=new DefaultTableModel(strKiemTra, 0);
        jTable1.setModel(tableModel);
        //lst=lstCTPM.;
        for(Object o: lstCTPM)
        {
            ChiTietPhieuMuon tg=(ChiTietPhieuMuon)o;
            lst.add(tg);
            Vector oneRow=new Vector();
           oneRow.add(tg.getPhieuMuonId());
            oneRow.add(tg.getSachId());
            oneRow.add(sachControl.GetObjByID(tg.getSachId(), "Sach").getTenSach());
            oneRow.add(pmControl.GetObjByID(tg.getPhieuMuonId(), "PhieuMuon").getNgayHenTra());
            lstdate.add(pmControl.GetObjByID(tg.getPhieuMuonId(), "PhieuMuon").getNgayHenTra());
            oneRow.add(tg.getTinhTrangSach());
            tableModel.addRow(oneRow);
          //  System.out.println(tableModel.);
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jPanel1 = new javax.swing.JPanel();
        lbTenDocGia = new javax.swing.JLabel();
        lbNgaySinh = new javax.swing.JLabel();
        lbGioiTinh = new javax.swing.JLabel();
        lbNgheNghiep = new javax.swing.JLabel();
        lbDonVi = new javax.swing.JLabel();
        lbNgayLamThe = new javax.swing.JLabel();
        lbNgayHetHan = new javax.swing.JLabel();
        lbEmail = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jLabel6 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null}
            },
            new String [] {
                "Mã phiếu mượn", "Mã sách", "Tên sách", "Ngày hẹn trả", "Tình trạng sách"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Integer.class, java.lang.Integer.class, java.lang.String.class, java.lang.Object.class, java.lang.String.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTable1MouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(jTable1);

        lbTenDocGia.setText("Tên độc giả : ");

        lbNgaySinh.setText("Ngày sinh : ");

        lbGioiTinh.setText("Giới tính :  ");

        lbNgheNghiep.setText("Nghề nghiệp : ");

        lbDonVi.setText("Đơn vị : ");

        lbNgayLamThe.setText("Ngày làm thẻ : ");

        lbNgayHetHan.setText("Ngày hết hạn : ");

        lbEmail.setText("Email : ");

        jButton1.setText("Hủy");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(31, 31, 31)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(lbTenDocGia, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lbNgaySinh, javax.swing.GroupLayout.PREFERRED_SIZE, 190, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lbNgheNghiep, javax.swing.GroupLayout.PREFERRED_SIZE, 199, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lbGioiTinh, javax.swing.GroupLayout.DEFAULT_SIZE, 180, Short.MAX_VALUE)
                            .addComponent(lbDonVi, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .addComponent(lbNgayLamThe, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(lbNgayHetHan, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(lbEmail, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jButton1)
                .addGap(26, 26, 26))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addComponent(lbTenDocGia, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbNgaySinh, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbGioiTinh, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(lbNgheNghiep, javax.swing.GroupLayout.DEFAULT_SIZE, 27, Short.MAX_VALUE)
                    .addComponent(lbDonVi, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lbNgayLamThe, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lbNgayHetHan, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbEmail, javax.swing.GroupLayout.DEFAULT_SIZE, 27, Short.MAX_VALUE)
                    .addComponent(jButton1))
                .addContainerGap())
        );

        jLabel6.setFont(new java.awt.Font("Tahoma", 0, 36)); // NOI18N
        jLabel6.setText("KIỂM TRA");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 651, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addGap(204, 204, 204)
                .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 212, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 216, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        dispose();
                
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MouseClicked
        // TODO add your handling code here:
       // int sachID=Integer.parseInt((String)jTable1.getValueAt(, 1));
     int row=(int)jTable1.getSelectedRow();
     int _sachID=lst.get(row).getSachId();
     Date _ngayhentra=lstdate.get(row);
     Sach obj=sachControl.GetObjByID(_sachID, "Sach");
     TraSachform.chonSach(obj, _ngayhentra);
     dispose();
    }//GEN-LAST:event_jTable1MouseClicked

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(KiemTraform.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(KiemTraform.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(KiemTraform.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(KiemTraform.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new KiemTraform().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JLabel lbDonVi;
    private javax.swing.JLabel lbEmail;
    private javax.swing.JLabel lbGioiTinh;
    private javax.swing.JLabel lbNgayHetHan;
    private javax.swing.JLabel lbNgayLamThe;
    private javax.swing.JLabel lbNgaySinh;
    private javax.swing.JLabel lbNgheNghiep;
    private javax.swing.JLabel lbTenDocGia;
    // End of variables declaration//GEN-END:variables

}
